package features.advance.jdk.concurrent;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * @author LIN
 * @date 2021-04-29
 */
public class Main {


    public static void main(String[] args) {
        ThreadFactory threadFactory = new ThreadFactoryBuilder().build();
        ExecutorService es = new ThreadPoolExecutor(4, 4,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(),threadFactory);
        for (int i = 0; i <6 ; i++) {
            es.submit(new Task(""+i));
        }
        // 关闭线程池
        es.shutdown();

    }
}

class Task implements Runnable {

    private final String name;

    public Task(String name){
        this.name = name;
    }



    @Override
    public void run() {
        System.out.println("start task "+name);
        try {
            Thread.sleep(1000);
        }catch (InterruptedException e){
            e.printStackTrace();
        }finally {
        }
        System.out.println("end task "+name);
    }
}
